import 'package:flutter/material.dart';
//import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:aweb5/util/WindowUtil.dart';
import 'dart:async';
import 'dart:convert';
class HomeTabWeb extends StatefulWidget {
  @override
  State<HomeTabWeb> createState() => _HomeTabWebState();
}

class _HomeTabWebState extends State<HomeTabWeb> {
  double width;
  WebViewController controller;


   String kNavigationExamplePage = '''
<!DOCTYPE html><html>
<head><title>Navigation Delegate Example</title></head>
<body>
<p>
The navigation delegate is set to block navigation to the youtube website.
</p>
<ul>
<ul><a href="https://www.youtube.com/">https://www.youtube.com/</a></ul>
<ul><a href="https://www.google.com/">https://www.google.com/</a></ul>
</ul>
<script>
function callJS(message){
  alert(message);
}
</script> 


</body>
</html>
''';


  @override
  void initState() {
    super.initState();
    width = 0;
  }

  @override
  Widget build(BuildContext context) {
    return buildBody();
//      WebviewScaffold(
//      url: "http://hhnh5.test.freshqiao.com",
//      withZoom: true,
//      withLocalStorage: true,
//      hidden: true,
//
//
//        initialChild:
//        Container(
//          child: Center(
//            child: new CircularProgressIndicator(
//              //0~1的浮点数，用来表示进度多少;如果 value 为 null 或空，则显示一个动画，否则显示一个定值
//                value: null,
//
//                //背景颜色
//                backgroundColor: Colors.white,
//                //进度颜色
//                valueColor: new AlwaysStoppedAnimation<Color>(Colors.grey)),
//          ),
//        )
//        ,
//
//
//
//    );
  }

  Widget buildBody() {
    return Stack(
      children: <Widget>[
        WebView(
          initialUrl: "http://hhnh5.test.freshqiao.com",
          javascriptMode: JavascriptMode.unrestricted,
          onPageFinished: (v) {
            width = 0;
            setState(() {});
          },
          onWebViewCreated: (WebViewController web){
            controller = web;
            String contentBase64 =
            base64Encode(const Utf8Encoder().convert(kNavigationExamplePage));
            controller.loadUrl('data:text/html;base64,$contentBase64');

          },
        ),
        Container(
          width: width,
          child: Center(
            child: new CircularProgressIndicator(
                //0~1的浮点数，用来表示进度多少;如果 value 为 null 或空，则显示一个动画，否则显示一个定值
                value: null,

                //背景颜色
                backgroundColor: Colors.white,
                //进度颜色
                valueColor: new AlwaysStoppedAnimation<Color>(Colors.grey)),
          ),
        )
      ],
    );
  }
}
